package com.zycfc.zsf.boot.logback.listener;

import ch.qos.logback.classic.spi.*;
import ch.qos.logback.core.spi.*;
import ch.qos.logback.core.*;
import com.zycfc.zsf.boot.util.net.*;
import java.io.*;
import ch.qos.logback.classic.*;

public class LoggerStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle
{
    private boolean started;
    
    public LoggerStartupListener() {
        this.started = false;
    }
    
    public void start() {
        if (this.started) {
            return;
        }
        final Context context = this.getContext();
        final String path = this.getLogPath();
        context.putProperty("zycfcLogPath", path);
        this.makeTempDir();
        this.started = true;
    }
    
    public String getLogPath() {
        final boolean isWinOrMac = OSUtils.isWin() || OSUtils.isMac();
        String path = "/home/zycfc/app/zycfc-app";
        if (isWinOrMac) {
            path = ".";
        }
        return path;
    }
    
    private void makeTempDir() {
        try {
            final boolean isLinux = OSUtils.isLinux();
            if (isLinux) {
                final File file = new File("/home/zycfc/app/zycfc-app/temp");
                if (!file.exists()) {
                    file.mkdirs();
                }
                final File uplodDir = new File("/home/zycfc/app/zycfc-app/temp/upload");
                if (!uplodDir.exists()) {
                    uplodDir.mkdirs();
                }
            }
        }
        catch (Throwable t) {}
    }
    
    public void stop() {
    }
    
    public boolean isStarted() {
        return this.started;
    }
    
    public boolean isResetResistant() {
        return false;
    }
    
    public void onStart(final LoggerContext context) {
    }
    
    public void onReset(final LoggerContext context) {
    }
    
    public void onStop(final LoggerContext context) {
    }
    
    public void onLevelChange(final Logger logger, final Level level) {
    }
}
